package com.ruoyi.system.utils;

import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.ruoyi.system.constant.XxConstant;
import lombok.SneakyThrows;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Objects;

/**
 * @Author LiBingyan
 * @Date 2022/3/20 17:50
 * @Version 1.0
 **/
public class XxUtils {
    /**
     * 获取对应水泥信息
     *
     * @param str
     * @return
     */
    public static List<String> getSectionCementList(String str) {
        switch (str) {
            case "TJ02标":
                return Lists.newArrayList(XxConstant.SN_TJ02_1JING, XxConstant.SN_TJ02_2JING);
            case "TJ03标":
                return Lists.newArrayList(XxConstant.SN_TJ03_1JING, XxConstant.SN_TJ03_2JING);
            case "TJ04标":
                return Lists.newArrayList(XxConstant.SN_TJ04_1JING, XxConstant.SN_TJ04_2JING);
            case "TJ01标":
            default:
                return Lists.newArrayList(XxConstant.SN_TJ01_1JING, XxConstant.SN_TJ01_2JING);
        }
    }

    /**
     * 获取对应实验信息
     *
     * @param str
     * @return
     */
    public static List<String> getSectionLabList(String str) {
        switch (str) {
            case "TJ02标":
                return Lists.newArrayList(XxConstant.SY_TJ02_KY, XxConstant.SY_TJ02_KYKZ, XxConstant.SY_TJ02_WNJ);
            case "TJ03标":
                return Lists.newArrayList(XxConstant.SY_TJ03_KY, XxConstant.SY_TJ03_KYKZ, XxConstant.SY_TJ03_WNJ);
            case "TJ04标":
                return Lists.newArrayList(XxConstant.SY_TJ04_KY, XxConstant.SY_TJ04_KYKZ, XxConstant.SY_TJ04_WNJ);
            case "中心实验室":
                return Lists.newArrayList(XxConstant.SY_TJZX_WNJ, XxConstant.SY_TJZX_KYKZ);
            case "TJ01标":
            default:
                return Lists.newArrayList(XxConstant.SY_TJ01_KY, XxConstant.SY_TJ01_KYKZ, XxConstant.SY_TJ01_WNJ);
        }
    }

    /**
     * 遍历类的属性有null或者""就返回false
     *
     * @param object
     * @return
     */
    @SneakyThrows
    public static Boolean checkBeanHasBlank(Object object) {
        Class identificationRequestParamClass = object.getClass();
        Field[] fields = identificationRequestParamClass.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            if (Objects.equals(field.get(object), null)) {
                return true;
            } else if (field.get(object) instanceof String) {
                if (StrUtil.hasBlank((CharSequence) field.get(object))) {
                    return true;
                }
            }
        }
        return false;
    }
}
